package com.ctrip.ec.biz.dao.goods;
import com.ctrip.ec.biz.entity.goods.GoodsEntity;
import com.ctrip.ec.dal.*;
import com.ctrip.ec.biz.entity.goods.GoodsCategoryEntity;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.List;

@Service
public class GoodsCategoryDao extends TreeDao<GoodsCategoryEntity> {
    public GoodsCategoryDao() {
        super(GoodsCategoryEntity.class);
    }
    public GoodsCategoryDao(DbAccess db) {
        super(GoodsCategoryEntity.class,db);
    }

    public boolean hasGoods(List<Long> ids) throws SQLException {
        if(ids.size()>0) {
            String strIds = IdConvert.join(ids);
            String sql = "select count(*) from " + EntityBase.getTableName(GoodsEntity.class) + " where " +
                    " cat_id in (" + strIds + ")";
            return this.db.getScalar(Long.class,sql) > 0;
        }
        else{
            return false;
        }
    }
}
